package com.appspot.moviesessions;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.ListView;

public class MovieListActivity extends FragmentActivity implements
		MovieListView {

	private MovieListPresenter presenter;
	private static final String TAG = "MovieListActivity";

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		AndroidFactory androidFactory = AndroidFactory.getInstance();
		this.presenter = new MovieListPresenter(this, new LoaderFactoryImpl(
				this, androidFactory, new ViewBinderFactoryImpl(
						getContentResolver(), androidFactory, androidFactory),
				androidFactory, androidFactory), androidFactory);
		presenter.onCreate();
	}

	@Override
	protected void onStart() {
		super.onStart();
		Log.v(TAG, "onStart");
		presenter.onStart();
	}

	@Override
	public Context getContext() {
		return this;
	}

	@Override
	protected void onStop() {
		super.onStop();
		Log.v(TAG, "onStop");
	}

	@Override
	protected void onPause() {
		super.onPause();
		Log.v(TAG, "onPause");
		presenter.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
		Log.v(TAG, "onResume");
		presenter.onResume();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		presenter.onDestroy();
		presenter = null;
	}

	@Override
	public ListView getMovieList() {
		return (ListView) findViewById(R.id.movie_list);
	}

}
